package com.hrt.datasender.web.bcserial;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import com.btcode.web.core.annotation.RequestMapping;
import com.btcode.web.core.controller.Controller;
import com.hrt.common.web.DSRequestUnit;
import com.hrt.datasender.datacollect.model.SerialProtocolModel;
import com.hrt.datasender.datadao.model.BcSerialModel;
import com.hrt.datasender.datadao.service.BcSerialService;

/**
 * 串口控制器
 * 
 * @author gislin
 *
 */
@RequestMapping(path = "BCSerial")
public class BCSerialController extends Controller {

    @RequestMapping(path = "getList")
    public void getModel(ServletRequest arg0, ServletResponse arg1) throws IOException {

        List<BcSerialModel> devices = BcSerialService.getInstance().getSerials();

        success(devices);
    }

    @RequestMapping(path = "create")
    public void saveModel(ServletRequest arg0, ServletResponse arg1) throws IOException {

        BcSerialModel model = DSRequestUnit.getModel(BcSerialModel.class);
        model = BcSerialService.getInstance().create(model);
        success(model);
    }

    @RequestMapping(path = "delete")
    public void delete(ServletRequest arg0, ServletResponse arg1) throws IOException {

        String id = DSRequestUnit.getString("id");
        BcSerialService.getInstance().delete(id);
        success("");

    }

    @RequestMapping(path = "update")
    public void update(ServletRequest arg0, ServletResponse arg1) throws IOException {

        BcSerialModel model = DSRequestUnit.getModel(BcSerialModel.class);
        BcSerialService.getInstance().update(model);
        success("");
    }

    @RequestMapping(path = "getProtocolList")
    public void getProtocolList(ServletRequest arg0, ServletResponse arg1)
            throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {

        List<SerialProtocolModel> models = BcSerialService.getInstance().getSerialProtocols();
        success(models);
    }
}
